/**
 * Handle changed data.
 *
 * @param {Object} oldValue old value
 * @param {Object} newValue new value
 * @param {JSEvent} event the event that triggered the action
 *
 * @returns {Boolean}
 *
 * @properties={typeid:24,uuid:"8B0F1E46-03E0-4C2E-9BEE-E9BF35F77745"}
 */
function onDataChange_codigo(oldValue, newValue, event) {
	if (controller.getSelectedIndex() == 1 && globals.gEstadoAbm == 1)
	{
		elements.nombre.requestFocus()
		return true
	}
	else
	{
		elements.nombre.requestFocus()
		codigo = oldValue
		return true
	}
}

/**
 * @properties={typeid:24,uuid:"E671444E-6E57-4232-A6CA-EEDC7CE69162"}
 */
function validar() {
	if (globals.gEstadoAbm == 1)
	{
		controller.setSelectedIndex(1)
		var $sql = 'SELECT codigo FROM provincias WHERE codigo = ?'
		var $args = [codigo]
		var $ds = databaseManager.getDataSetByQuery('contable',$sql,$args,-1)
		if ($ds.getMaxRowIndex() != 0) 
		{		
			return [false,"El código ingresado ya existe"]
		}
	}
	return [true]
}

/**
 * @properties={typeid:24,uuid:"F9CBDCB4-20D8-4442-9495-732767C614F3"}
 */
function imprimir()
{
	//forms.provincias_tbl_impresion.controller.showPrintPreview()
	jasper('impresion')
}

/**
 * @properties={typeid:24,uuid:"87994EB8-EDC5-4B74-9FE1-17D997C72A6A"}
 */
function pdf()
{
	//globals.metodoPdf('provincias_tbl_impresion','Provincias - '+globals.glegajo,true)
	jasper('pdf')
}

/**
 * @properties={typeid:24,uuid:"306F00B7-0782-434A-8652-6D507F5A5EDD"}
 */
function xls()
{
	jasper('xls')
}

/**
 * @properties={typeid:24,uuid:"2BB67706-3D74-4D0A-A6E8-E531BD4EC380"}
 */
function csv()
{
	jasper('csv')
}

/**
 * @param {String} tipo
 *
 * @properties={typeid:24,uuid:"0CF9DF8C-DE0B-4DD7-8D28-93411DE34BD2"}
 */
function jasper(tipo)
{
	var $params = {
		userv: usuarios_to_uservs.razon_social
	}
	
	globals.metodoJasper(tipo,'contable/provincias.jasper','Provincias',foundset,$params)
}